package com.ljx.video.oss;

import cn.hutool.extra.spring.SpringUtil;
import com.ljx.video.domain.vo.req.FileUploadReq;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.InputStream;

@Service
public class OssService {

    @Value("${oss.type}")
    private Integer type;

    public void uploadChunk(FileUploadReq req) {
        OssStrategy ossStrategy = getOssStrategy();
        ossStrategy.upload(req);
    }

    public void mergeChunk(FileUploadReq req) {
        OssStrategy ossStrategy = getOssStrategy();
        ossStrategy.merge(req);
    }

    private OssStrategy getOssStrategy() {
        if (type.equals(1)) {
            return SpringUtil.getBean(LocalStrategy.class);
        } else {
            return SpringUtil.getBean(MinioStrategy.class);
        }
    }

    public InputStream download(Long id, String tsNum) {
        OssStrategy ossStrategy = getOssStrategy();
        return ossStrategy.download(id, tsNum);
    }
}
